From: John Johansen Date: Tue, 3 Mar 2026 19:08:02 +0000 (-0800) Subject: [PATCH 04/11] apparmor: fix: limit the number of levels of policy namespaces X-Git-Tag: archive/raspbian/6.19.6-2+rpi1~3^2~23 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com//%22draghici.adrian.b%40gmail.com/%22/%22http:/www.example.com/%22draghici.adrian.b%40gmail.com/%22?a=commitdiff_plain;h=c5f887add0261202bc280ea4a44b99718ed47256;p=linux.git [PATCH 04/11] apparmor: fix: limit the number of levels of policy namespaces Currently the number of policy namespaces is not bounded relying on the user namespace limit. However policy namespaces aren't strictly tied to user namespaces and it is possible to create them and nest them arbitrarily deep which can be used to exhaust system resource. Hard cap policy namespaces to the same depth as user namespaces. Fixes: c88d4c7b049e8 ("AppArmor: core policy routines") Reported-by: Qualys Security Advisory Reviewed-by: Ryan Lee Reviewed-by: Cengiz Can Signed-off-by: John Johansen Gbp-Pq: Topic bugfix/all/qsa-2026-apparmor Gbp-Pq: Name 0004-apparmor-fix-limit-the-number-of-levels-of-policy-na.patch --- diff --git a/security/apparmor/include/policy_ns.h b/security/apparmor/include/policy_ns.h index d646070fd96..cc6e8415181 100644 --- a/security/apparmor/include/policy_ns.h +++ b/security/apparmor/include/policy_ns.h @@ -18,6 +18,8 @@ #include "label.h" #include "policy.h" +/* Match max depth of user namespaces */ +#define MAX_NS_DEPTH 32 /* struct aa_ns_acct - accounting of profiles in namespace * @max_size: maximum space allowed for all profiles in namespace diff --git a/security/apparmor/policy_ns.c b/security/apparmor/policy_ns.c index 64783ca3b0f..ff49a31ac27 100644 --- a/security/apparmor/policy_ns.c +++ b/security/apparmor/policy_ns.c @@ -223,6 +223,8 @@ static struct aa_ns *__aa_create_ns(struct aa_ns *parent, const char *name, AA_BUG(!name); AA_BUG(!mutex_is_locked(&parent->lock)); + if (parent->level > MAX_NS_DEPTH) + return ERR_PTR(-ENOSPC); ns = alloc_ns(parent->base.hname, name); if (!ns) return ERR_PTR(-ENOMEM);